<template>
  <el-pagination
    @current-change="handleCurrentChange"
    :current-page.sync="currentPage"
    layout="total, prev, pager, next, jumper"
    :page-size="pageSize"
    :total="total">
  </el-pagination>
</template>

<script>
  export default {
    name: "Pagination",
    methods: {
      handleCurrentChange(val) {
        // 用户点击时，将当前页val传给父组件
        this.$emit("getCurrentPage", val);
      }
    },
    data() {
      return {
        currentPage: 1,
      };
    },
    props: {
      pageSize: {
        type: Number,
        default: 10
      },
      total: {
        type: Number,
        default: 0
      },
      cp: { // 父组件中如果需要修改当前页，那么要把这个cp传过来
        type: Number,
        default: 0
      }
    },
    watch: {
      cp: function(newVal) {
        if (this.cp !== 0) {
          this.currentPage = newVal;
        }
      }
    }
  }
</script>

<style scoped>
  .el-pagination {
    margin-top: 20px;
    float: right;
    margin-right: 5%;
  }

</style>

<style>
  input[type="number"] {
    height: 28px !important;
  }

  .el-pager>li {
    border: 1px solid #eee !important;
    border-right: none !important;
    color: #666 !important;
  }

  .el-pager>li:last-child {
    border-right: 1px solid #eee !important;
  }

  .el-pager>.active {
    background-color: #409EFF !important;
    color: #fff !important;

  }
</style>